#include <iostream>
#include <unistd.h>
#include "scheduler.cpp"


using namespace std;

int main() {
  
  char trace[256] = "t1.trace";

  cout << endl;
  cout << "Starting..." << endl;

  SchedulerReturn sr;
  sr.return_code = SRET_SUCCESS;
  int scheduling_policy = 0;
  int clockDelay = 3;
  Scheduler* s = new Scheduler(scheduling_policy);

  Process* p = new Process(0, trace);
  s->AddProcess(0, p);

  while (sr.return_code != SRET_NO_PROCESSES)
  {
     sr = s->run();     
     cout << "Run output: " << sr.return_code << endl;

     if (sr.return_code == SRET_SYSCALL){
       cout << "Add to block IO queue: " << sr.vals.sysCall.pid << endl;
     }
     else if (sr.return_code == SRET_NEW_PROCESS){
       Process* p = new Process(sr.vals.newProcess.pid,sr.vals.newProcess.file_name);
       s->AddProcess(sr.vals.newProcess.pid, p);
       cout << "Create new process: pid = " << sr.vals.newProcess.pid << endl;
     }
     sleep(clockDelay);
  }
  cout << "Exiting..." << endl;
}
